package com.ftg.wymall.rabbit.chapter04;

import com.rabbitmq.client.*;

/**
 * 路由的接收者
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/11/30 上午9:01
 */
public class SubscribeReceving02 {

    public static void main(String[] args) {
        System.out.println("会员");
        try {
            ConnectionFactory factory = new ConnectionFactory();
            factory.setHost("localhost");
            Connection connection = factory.newConnection();
            Channel channel = connection.createChannel();


            channel.exchangeDeclare("direct_logs", BuiltinExchangeType.DIRECT);

            AMQP.Queue.DeclareOk declareOk = channel.queueDeclare("", false, true, false, null);


            String queue = declareOk.getQueue();

            channel.queueBind(queue, "direct_logs", "black2");

            System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

            //对接收到的信息进行回调处理
            DeliverCallback deliverCallback = (consumerTag, delivery) -> {
                String message = new String(delivery.getBody(), "UTF-8");
                System.out.println(" [x] Received '" + message + "'");

                //mapper openfeign  业务处理

            };
            /**
             * basicConsume 接收消息
             * queueDeclare 声明队列
             * autoAck 自动确认
             * deliverCallback 回调处理
             * consumerTag 回调标识 相当于取消以后要执行的操作
             */
            channel.basicConsume(queue, true, deliverCallback, consumerTag -> { });

        }catch (Exception e) {
            e.printStackTrace();
        }

    }

}
